package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_Product;

import com.openbravo.bean.Product;
import com.openbravo.bean.ProductCode;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class ProductCodeDAO extends ModifiedLogDAO<ProductCode>{

	public ProductCodeDAO(I_Session s) {
		super(s);
	}


	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "PRODUCTS_CODE",
                new Field[]{
                  new Field("ID", Datas.STRING, Formats.STRING),
                  new Field("PRODUCT", Datas.STRING, Formats.STRING,Product.class),
                  new Field("CODE", Datas.STRING, Formats.STRING),
                  new Field(I_Product.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP) 
		},
        new int[]{0});
	}

	@Override
	public void writeInsertValues(DataWrite dp, ProductCode obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setString(2,obj.getProductId());
		dp.setString(3,obj.getCode());
		dp.setTimestamp(4,obj.getLastModified());
		
	}


	@Override
	public ProductCode readValues(DataRead dr,ProductCode pCode) throws BasicException {
		if(pCode==null)
			pCode=new ProductCode();
		pCode.setId(dr.getString(1));
		pCode.setProductId(dr.getString(2));
		pCode.setCode(dr.getString(3));
		pCode.setLastModified(dr.getTimestamp(4));
		return pCode;
	}
	
	
	@Override
	public Class getSuportClass() {
		return ProductCode.class;
	}

}
